/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package POJO;

import DB.ContentContainerManager;
import DB.DBInfo;
import DB.TripManager;
import java.util.HashMap;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Sibrand
 */
public class Trips {

    private HttpSession session;

    public Trips(HttpSession session) {
        this.session = session;
    }

    public String addContentContainer() {
        if (session.getAttribute("user") != null && ((User) session.getAttribute("user")).username != null) {
            ContentContainerManager db = new ContentContainerManager(DBInfo.getConnection());
            TripManager t = new TripManager(db.conn);
            int[] trips = t.getTripsOwnedBy(((User) session.getAttribute("user")).username);
            String result = "<form action=\"addTrip\" method=\"post\"><table>";
            result += "<tr><td>Add to trip</td><td><select><option>Start new trip</option></select>";

            for (int i = 0; i < trips.length; ++i) {
                String temp = "";
                int[] ids = db.getAllContentContainersOfTripForOwners(trips[i]);
                for (int j = 0; j < ids.length && j == 0; ++j) {
                    HashMap<String, String>[] hash = db.getRows("ContentContainers", "containerID", String.valueOf(ids[j]));

                    String date = hash[1].get("createdOn");
                    temp += " (created on " + date + ")";
                }

                if (temp.compareTo("") == 0) {
                    result += "<option value=\"" + i + "\">Trip " + i + " (empty)</option>";
                } else {
                    result += "<option value=\"" + i + "\">Trip " + i + temp + "</option>";
                }
            }

            //in te vullen via JS m.b.v. Google Maps ?
            result += "</td></tr><tr><td><br />Longitudinal coordinate:</td><td><br /><input type=\"text\" name=\"long\" /></td></tr>";
            result += "<tr><td>Latitudinal coordinate:</td><td><input type=\"text\" name=\"lat\" /></td></tr>";

            result += "<tr><td valign=\"top\"><br />Story:</td><td><br /><textarea name=\"story\" rows=\"15\" cols=\"75\"></textarea></td></tr>";

            result += "<tr><td valign=\"top\">Videos:</td><td><table id=\"tblVideos\"><tr><td><input type=\"button\" value=\"Add Video (as link)\" onclick=\"addRowToVTable();\" /></td></tr></table></td></tr>";
            result += "<tr><td valign=\"top\">Pictures:</td><td><table id=\"tblPictures\"><tr><td><input type=\"button\" value=\"Add Picture (as link)\" onclick=\"addRowToPTable();\" /></td></tr></table></td></tr>";


            result += "</table></form>";

            return result;
        } else {
            return "<h3>You need to log in before you can start or expand trips.</h3>";
        }
    }
}
